
#ifndef GAME_DRAWER_H_INCLUDED
#define GAME_DRAWER_H_INCLUDED

#include <freeglut.h> 
#include "SOIL.h"
#include <vector>

using namespace std;
class UI;
class Game;
class Color;
class Texture;
class Coord;

static bool use_fill = true;
static bool use_stroke = true;
static bool use_texture = false;
static GLuint texture1;
static vector<Texture *> textures;
static int window_width;
static int window_height;
int get_window_width();
int get_window_height();

//camera
static float camera_defaultScale = 1;
static float camera_scale = 1;
static float camera_minScale = 0.25;
static float camera_maxScale = 5;
static float camera_x = 0;
static float camera_y = 0;	
static float camera_zoom_speed = 0.001f;
static float camera_scroll_speed = 2;
float get_camera_x();
float get_camera_y();
//mouse
bool mouse_left();
bool mouse_right();
bool mouse_middle();
void mouse_left_pressed();
void mouse_right_pressed();
void mouse_middle_pressed();
void mouse_left_released();
void mouse_right_released();
void mouse_middle_released();
void mouse_set_position(int x, int y);
static bool mouse_lmb = false;
static bool mouse_rmb = false;
static bool mouse_mmb = false;


//represents a 2D coordinate
class Coord{
public:
	Coord(){
		x = 0;
		y = 0;
	}
	Coord(int xIn, int yIn);
	int x;
	int y;
private:
};

Coord mouse_get_position();
Coord mouse_get_world_position();
static Coord mouse_pos = Coord(0,0);
static Coord mouse_worldPos = Coord(0,0);

class Color{
	public:
		float r;
		float g;
		float b;
		float a;
		Color(int r, int g, int b);
		Color(int r, int g, int b, int a);
		Color(float r, float g, float b);
		Color(float r, float g, float b, float a);
		Color(){
			r = g = b = a = 255;
		};
};

static Color fill_color;
static Color stroke_color;

//Maitains the state of the game by using an enclosed Game object, and takes
//care of drawing the game
class GameDrawer {
	private:
		UI* ui;
		Game* game;
		void step();

	public:
		GameDrawer(int, int);
		~GameDrawer();
		void draw();
		void handleMouseInput(int button, int state, int x, int y );
		void handleKeyboardInput(unsigned char key, int x, int y );
		void moveMouse(int x, int y);//called for all mouse position updates
		void moveActive(int x, int y);//called when mouse is dragged
		void updateSize(int newW, int newH);
		void loadTextures();
		//Advances the state of the game by the specified amount of time
		void advance(float dt);	
};

class Texture{
public:
	Texture(string s){
		string str = "Textures\\";
		str.append(s);
		printf("loading: %s\n",s.c_str());
		ID = SOIL_load_OGL_texture(s.c_str(),
			SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID,
			SOIL_FLAG_INVERT_Y);
		name = s;
	}
	string getName();
	GLuint getID();
private:
	string name;
	GLuint ID;
};

void glEnable2D();
void glDisable2D();

void glTranslate2f(float x, float y);

void updateSize(int newW, int newH);

void setColor(Color color);
void lineWidth(float width);

void fill();
void fill(Color c);
void stroke();
void stroke(Color c);
void noFill();
void noStroke();
void useTexture(GLuint);
void noTexture();

//camera stuff
void zoomIn();
void zoomOut();
void resetZoom();
void moveCamera(float,float);
void setCamera(float,float);

void drawCircle(float x, float y, float r);
void drawCircle(Coord pos, float r);
void drawRect(float x1, float y1, float x2, float y2);
void drawRect(Coord,Coord);
void drawLine(float x1, float y1, float x2, float y2, Color c);
void drawLine(float x1, float y1, float x2, float y2, Color c, int width);
void renderBitmapString(Coord position, string* str, Color c);
void renderBitmapString(Coord position, string* str);
void rectHelper(float,float,float,float);
GLuint findTexture(string);
//void drawTexRect(float x1, float y1, float x2, float y2);
//GLuint loadImage(const char* theFileName);
#endif
